package mrusanov.view

import java.awt.{Graphics2D, Graphics}
import mrusanov.images.{ImageInfo, Image}

trait Sprite {
  val frameTime = 100

  var x = 0
  var y = 0

  def isOver:Boolean

  def render(g:Graphics2D)

  def render(g:Graphics2D, x:Int, y:Int) {
    this.x = x
    this.y = y
    render(g)
  }

  def update(time:Int):Boolean

  def index:Int

  def reset()
}

object Sprite {
  private val HOST_FOLDER = ""//"/blue"
  private val GUEST_FOLDER = ""//"red"

  def apply(info:Vector[ImageInfo], host:Boolean):Sprite = {
     new AnimatedSprite(images(info, host))
  }

  private def images(info:Vector[ImageInfo], host:Boolean):Vector[Image] = {
    val retList = for(in <- info) yield {
      val cloned = in.cloneWithPath(folderPath(host, in.path))
      cloned.buildImage
    }

    Vector() ++ retList
  }

  private def folderPath(host:Boolean, path:String):String = {
    host match {
      case true => path + HOST_FOLDER
      case false => path + GUEST_FOLDER
    }
  }
}
